package com.example.partition;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SalaryTotalMain {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 1. 创建一个job和任务入口(指定主类)
        Job job = Job.getInstance(new Configuration());
        job.setJarByClass(SalaryTotalMain.class);
        //2. 指定job的mapper和输出的类型<k2 v2>
        job.setMapperClass(SalaryTotalMapper.class);
        job.setMapOutputKeyClass(IntWritable.class);
        //job.setMapOutputValueClass(IntWritable.class);
        job.setMapOutputValueClass(Employee.class);//map阶段的输出类型
        //3. 指定job的reducer和输出的类型<k4  v4>
        job.setReducerClass(SalaryTotalReduce.class);
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);
        //指定自定义数据分区
        job.setPartitionerClass(DeptPartitioner.class);
        //同时指定相应数量的reduce task
        job.setNumReduceTasks(3);
        //4. 指定job的输入和输出路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //5. 执行job
        job.waitForCompletion(true);

    }
}
